package com.herui.ota.controller;

import com.herui.ota.config.ControllerNames;
import com.herui.ota.entity.User;
import com.herui.ota.pojo.form.*;
import com.herui.ota.pojo.vo.UserVo;
import com.herui.ota.service.UserService;
import com.herui.ota.service.iml.BaseService;
import com.mlnx.common.annotations.NeedLogin;
import com.mlnx.common.entity.Response;
import com.mlnx.common.entity.ResponseData;
import com.mlnx.common.form.PageForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.shan.base.layer.user.service.UserAccountService;
import org.shan.spring.base.UrdBaseController;
import org.shan.spring.base.annotations.SysLog;
import org.shan.spring.mybatis.service.ICurdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by amanda.shan on 2020/5/19.
 */
@Api(value = ControllerNames.UserName + "接口", tags = {ControllerNames.UserName + "接口"})
@SysLog(title = ControllerNames.UserName)
@RestController
@RequestMapping("/user")
public class UserController extends UrdBaseController<User, UserForm, UserFilterForm> {

    @Autowired
    private UserService service;

    @Autowired
    private UserAccountService userAccountService;

    @Override
    public ICurdService getService() {
        return service;
    }

    @Override
    public User newInstance(Integer id) {
        User user = new User();
        user.setId(id);
        return user;
    }

    @ApiOperation(value = "用户登入 真实url /oauth/token 和lifeport方式一样", notes = "")
    @PostMapping("/login")
    public Response login(LoginForm loginForm, HttpServletRequest request,
                          HttpServletResponse response) throws ServletException, IOException {
        return result();
    }

    @ApiOperation("导出excel列表")
    @GetMapping("/excel")
    public void getMqttParamById(PageForm pageForm, UserFilterForm filter, HttpServletResponse response) throws IllegalAccessException {
        BaseService baseService = (BaseService) service;
        baseService.pageExcel( pageForm, filter,response);
    }

    @NeedLogin
    @ApiOperation(value = "获取用户信息", notes = "")
    @GetMapping("/info")
    public ResponseData<UserVo> getUserInfo() {

        return result(service.getUserInfo());
    }

    @ApiOperation(value = "获取用户数量", notes = "")
    @GetMapping("/size")
    public ResponseData<Integer> getUserSize() {

        return result(service.getUserSize());
    }
}
